package com.wanyangproject.androidlearning.multiThread.energyConservation;

public class EnergyTransferTask implements Runnable {

    private Energy energy;
    private int from;
    private int max;


    public EnergyTransferTask(Energy energy, int from, int max) {
        this.energy = energy;
        this.from = from;
        this.max = max;
    }

    @Override
    public void run() {
        while (true){
            int toBox = (int) (energy.getBoxNum() * Math.random());
            double amount = (max * Math.random());
            energy.transfer(from, toBox, amount);
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }


}
